﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MiniCPU.Entities;

namespace MiniCPU
{
    /// <summary>
    /// Emulator Form.
    /// </summary>
    public partial class Emulator : Form
    {
        public CPU cpu;

        /// <summary>
        /// Initializes a new instance of the <see cref="Emulator"/> class.
        /// </summary>
        public Emulator()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Handles the Load event of the Form1 control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void Form1_Load(object sender, EventArgs e)
        {
            Register IR = new Register(32, "IR");
            IR.Clear.BooleanValue = true;
            DataPropagator SELA = new DataPropagator("IR(7..0)", IR, 7, 0);
            Clock.Tick();
            MessageBox.Show(SELA.IntValue.ToString());
            IR.Clear.BooleanValue = false;
            IR.Increment.BooleanValue = true;
            Clock.Tick();
            MessageBox.Show(SELA.IntValue.ToString());
            Clock.Tick();
            MessageBox.Show(SELA.IntValue.ToString());

            /*this.cpu = new CPU();
            Dictionary<int, LimitedData> program = new Dictionary<int, LimitedData>();
            program.Add(00, new LimitedData(String.Empty, "00001000", 2, 8));
            program.Add(01, new LimitedData(String.Empty, "01001001", 2, 8));
            program.Add(02, new LimitedData(String.Empty, "11000001", 2, 8));
            program.Add(03, new LimitedData(String.Empty, "00001010", 2, 8));
            program.Add(04, new LimitedData(String.Empty, "01001100", 2, 8));
            program.Add(05, new LimitedData(String.Empty, "11000010", 2, 8));
            program.Add(06, new LimitedData(String.Empty, "00001011", 2, 8));
            program.Add(07, new LimitedData(String.Empty, "10000001", 2, 8));
            program.Add(08, new LimitedData(String.Empty, "00000000", 2, 8));
            program.Add(09, new LimitedData(String.Empty, "00001000", 2, 8));
            program.Add(10, new LimitedData(String.Empty, "00111111", 2, 8));
            program.Add(11, new LimitedData(String.Empty, "00011111", 2, 8));
            program.Add(12, new LimitedData(String.Empty, "00000101", 2, 8));

            this.cpu.Memory.LoadProgram(program);
            this.cpu.PC.IntValue = 0;

            this.propertyGrid1.SelectedObject = this.cpu;*/
        }

        void SELA_DataChanged(object sender, MiniCPU.Events.DataChangedEventArgs e)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Handles the Click event of the btnTick control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnTick_Click(object sender, EventArgs e)
        {
            Clock.Tick();
            this.propertyGrid1.SelectedObject = this.cpu;
        }
    }
}
